package com.dctp.common.disruptor.close;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.plugin.activerecord.Record;

import java.util.HashMap;
import java.util.Map;

public class CloseOrder {

    private Record order;
    private Record updateUser;
    private Record orderFundFlow;
    private Record serviceFeeFundFlow;


    public CloseOrder() {

    }

    public CloseOrder(Record order, Record updateUser, Record orderFundFlow, Record serviceFeeFundFlow) {
        this.order = order;
        this.updateUser = updateUser;
        this.orderFundFlow = orderFundFlow;
        this.serviceFeeFundFlow = serviceFeeFundFlow;
    }

    public Record getOrder() {
        return order;
    }

    public void setOrder(Record order) {
        this.order = order;
    }

    public Record getUpdateUser() {
        return updateUser;
    }

    public void setUpdateUser(Record updateUser) {
        this.updateUser = updateUser;
    }

    public Record getOrderFundFlow() {
        return orderFundFlow;
    }

    public void setOrderFundFlow(Record orderFundFlow) {
        this.orderFundFlow = orderFundFlow;
    }

    public Record getServiceFeeFundFlow() {
        return serviceFeeFundFlow;
    }

    public void setServiceFeeFundFlow(Record serviceFeeFundFlow) {
        this.serviceFeeFundFlow = serviceFeeFundFlow;
    }


    // ✅ 生成 JSON 字符串
    public String toJson() {
        try {

            Map<String,Object> map = new HashMap<>();

            map.put("order", order.toJson());
            map.put("updateUser", updateUser.toJson());
            map.put("serviceFeeFundFlow", serviceFeeFundFlow.toJson());
            // 可能为空的字段要判断
            map.put("orderFundFlow", orderFundFlow != null ? serviceFeeFundFlow.toJson(): "");
            return JSON.toJSONString(map);
        } catch (Exception e) {
            throw new RuntimeException("❌ CloseOrder.toJson() 失败", e);
        }
    }
}
